package com.chinanet.utils.telnet;

import java.net.Socket;
import java.util.Map;

public class TelnetTest {
    public static void main(String args[]){
        test2();
    }
    public static void test1(){
        Socket2Telnet s = new Socket2Telnet(new Socket(), "134.96.213.68", 21123);
        s.getIns().add("tz.skb");
        s.getIns().add("tz.skb111");
        s.getIns().add("SET AMO:NAME=\"HZMMTEL202-SSS_141\"");
        s.getIns().add("get");
        s.getIns().add("SHOW OSU SBR:PUI=\"tel:+8657688910054\"");
        s.setProp("$HZMMTEL202-SSS_141>");
        s.run();
        if (s.getResult() != null) {
            System.out.println("成功获取数据");
        } else {
            System.out.println("发生错误");
        }
        Map<String, Object> outmap;
        String pattern = "\\S+|=|\\S*\\n";
        // 将结果进行格式化
        String result = s.getResult().toString().replaceAll("( )+","|=|");
        System.out.println("----------原始数据:-----------");
        System.out.println(result);
        System.out.println("------------------------");
        outmap = ITelnet.matching(pattern, result);
        for (Map.Entry<String, Object> e : outmap.entrySet()) {
            System.out.println(e.getKey() + ":" + e.getValue());
        }
    }
    public static  void test2(){
        Socket2Telnet s = new Socket2Telnet(new Socket(), "134.96.213.68", 21123);
        s.getIns().add("tz.skb");
        s.getIns().add("tz.skb111");
        s.getIns().add("SET AMO:NAME=\"HZAGCF201-AGCF_51\"");
        s.getIns().add("get");
        s.getIns().add("SHOW NODE:BEGIN=4000111");
        s.setProp("$HZAGCF201-AGCF_51>");
        s.run();
        if (s.getResult() != null) {
            System.out.println("成功获取数据");
            System.out.println(s.getResult().toString());
        } else {
            System.out.println("发生错误");
        }
        Map<String, Object> outmap;
        String pattern = "\\S+\\s+\\|[\\S+\\s+\\|]+\\S+\\s+";
        // 将结果进行格式化
        String result =s.getResult().toString().replaceAll("( ){2,}","\\|");
        System.out.println("----------原始数据:-----------");
        System.out.println(result);
        System.out.println("------------------------");
        outmap = ITelnet.matchingTable(pattern, result);
        outmap.put("log",result);
        for (Map.Entry<String, Object> e : outmap.entrySet()) {
            System.out.println(e.getKey() + ":" + e.getValue());
        }
    }
    public static  void test3(){
        Socket2Telnet s = new Socket2Telnet(new Socket(), "134.96.213.68", 21123);
        s.getIns().add("tz.skb");
        s.getIns().add("tz.skb111");
        s.getIns().add("SET AMO:NAME=\"HZAGCF201-AGCF_51\"");
        s.getIns().add("get");
        s.getIns().add("SHOW NODE:BEGIN=4000111");
        s.setProp("$HZAGCF201-AGCF_51>");
        s.run();
        if (s.getResult() != null) {
            System.out.println("成功获取数据");
            System.out.println(s.getResult().toString());
        } else {
            System.out.println("发生错误");
        }
        Map<String, Object> outmap;
        String pattern = "\\S+\\s+\\|[\\S+\\s+\\|]+\\S+\\s+";
        // 将结果进行格式化
        String result =s.getResult().toString().replaceAll("( ){2,}","\\|");
        System.out.println("----------原始数据:-----------");
        System.out.println(result);
        System.out.println("------------------------");
        outmap = ITelnet.matchingTable(pattern, result);
        outmap.put("log",result);
        for (Map.Entry<String, Object> e : outmap.entrySet()) {
            System.out.println(e.getKey() + ":" + e.getValue());
        }
    }
}
